package com.sjs.boot.dynamic.core.config.method.process;


import com.sjs.boot.dynamic.core.config.method.MethodConfig;
import com.sjs.boot.dynamic.core.run.MethodContext;
import com.sjs.boot.dynamic.facade.config.AbstractProcessConfig;
import com.sjs.boot.dynamic.util.ValParser;

import java.util.Map;

/**
 * @author uto_dev_008
 * @desc 只需要数据源，不需要框架处理数据库操作
 * @since 2021/11/10 18:14
 */
public class SelfRDBProcessConfig extends AbstractProcessConfig {
    private static final String PARAMETER_TRANSACTION = "transaction";
    private static final String PARAMETER_DATASOURCE = "dataSource";

    private boolean transaction = false; //是否使用事务
    //todo 暂时写死
    private String dataSource = "main"; //数据库资源


    @Override
    protected boolean parseExt(String ver, Map<String, Object> json, MethodConfig mc) {
        transaction = ValParser.getAsBool(json, PARAMETER_TRANSACTION, transaction);
        dataSource = ValParser.getAsStr(json, PARAMETER_DATASOURCE, dataSource);

        return true;
    }

    public boolean useTransaction() {
        return transaction;
    }

    public String getDataSource(MethodContext context) {
        return dataSource;
    }

    public String getDataSource() {
        return dataSource;
    }
}
